package com.lry.pda.bottom.c.backend.executor;

import com.lry.pda.bottom.c.backend.code.CodeKey;
import com.lry.pda.bottom.c.backend.code.CodeNode;

import java.util.Collections;


public abstract class BaseExecutor implements Executor{

    protected static Object returnObj;
    protected static boolean continueExecute = true;

    protected void executeChildren(CodeNode root) {
        for (CodeNode child : root.getChildren()) {
            if(!continueExecute){
                break;
            }
            Executor executor = ExecutorFactory.getExecutor(child);
            if (executor != null) {
                executor.execute(child);
            }
        }
    }

    protected CodeNode executeChild(CodeNode root, int childIdx) {
        CodeNode child = root.getChildren().get(childIdx);
        Executor executor = ExecutorFactory.getExecutor(child);
        if(null!=executor){
            executor.execute(child);
        }
        return child;
    }
    protected void copyChild(CodeNode root, CodeNode child) {
        root.setAttr(CodeKey.SYMBOL, child.getAttr(CodeKey.SYMBOL));
        root.setAttr(CodeKey.VALUE, child.getAttr(CodeKey.VALUE));
        root.setAttr(CodeKey.TEXT, child.getAttr(CodeKey.TEXT));
    }

}
